<%--
  Created by IntelliJ IDEA.
  User: user
  Date: 2024/12/12
  Time: 14:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/jquery-1.11.3.min.js"></script>
</head>
<body>
<div>
    <form action="/Hymall/admin/product/search" method="post">
        <div>
            <label>产品名称</label>
            <input name="productName" placeholder="请输入产品名称">
        </div>
        <div>
            <label>产品类型</label>
            <select name="categoryId">
                <option value="0">全部</option>
                <c:forEach items="${categories}" var="category">
                    <option value="${category.categoryId}">${category.categoryName}</option>
                </c:forEach>
            </select>
        </div>
        <div>
            <button type="submit">提交</button>
            <button type="reset">重置</button>
        </div>
    </form>
    <button id="btn-add">新增</button>
</div>

<div>
    <table>
        <thead>
        <tr>
            <td>序号</td>
            <td>产品名称</td>
            <td>产品类型</td>
            <td>产品价格</td>
            <td>产品标题</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${productList}" var="product">
            <tr>
                <td>${product.productId}</td>
                <td>${product.productName}</td>
                <td>${product.categoryName}</td>
                <td>${product.productSalePrice}</td>
                <td>${product.productTitle}</td>
                <td>
                    <button class="pro_del" mid="${product.productId}">删除</button> &nbsp;
                    &nbsp;
                    <button class="pro_detail" mid="${product.productId}">详情</button>
                    <a href="/Hymall/admin/product/detail?productId=${product.productId}">详情链接</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<style>
    #conten-add{
        width: 300px;
        height: 200px;
        position: fixed;
        top: 50%;
        margin-top: -100px;
        left: 50%;
        margin-left: -150px;
        background-color: #fff;
    }
</style>


<div id="conten-add">
    <form action="/Hymall/admin/category/add" method="post">
        <input name="categoryName" id="add-cname" placeholder="类别名称">
        <input name="categoryImageSrc" id="add-cimg" placeholder="图片地址">
<%--        form表单内按钮需要是submit 才能提交--%>
        <button type="submit">提交</button>
        <button type="reset" id="btn-cancle">取消</button>
    </form>
</div>

<script>
    $(function () {
        $('.pro_del').click(function () {
            let id = $(this).attr('mid');
            $.ajax({
                url: '/Hymall/admin/product?productId=' + id,
                method: 'delete',
                // data:{'productId':id},
                success: function (res) {
                    console.log(res);
                }
            })
        });
        $('.pro_detail').click(function (){
            let id = $(this).attr('mid');
            $.ajax({
                url: '/Hymall/admin/product/detail?productId='+id,
                method: 'get',
                success:function (res){

                }
            })
        });
        $('#conten-add').hide();
        $('#btn-add').click(function (){
            $('#conten-add').show();
        });
        $('#btn-cancle').click(function (){
            $('#add-cname').val('');
            $('#add-cimg').val('');
            $('#conten-add').hide();
        });

    });
</script>

</body>
</html>
